package org.ccunix.eshop.service;
import java.util.List;
import org.ccunix.eshop.dao.CategroyDAO;
import org.ccunix.eshop.dao.MerchandiseDAO;
import org.ccunix.eshop.model.CategoryModel;
import org.ccunix.eshop.model.MerchandiseModel;
public class MerchandiseManagerService{
	CategroyDAO  categroyDAO = new  CategroyDAO();
	MerchandiseDAO merchandiseDAO = new MerchandiseDAO();
	public List<CategoryModel> findCateList(){
		try{
			return categroyDAO.queryCateList();
		} catch (Exception e){
			e.printStackTrace();
		}
		return null;
	}
	public List<MerchandiseModel> findMerList(int special) {
		try {
			return  merchandiseDAO.getMerList(special);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	return null;
	}
	public MerchandiseModel findMerById(String id){
		try {
			int int_id = Integer.parseInt(id);
			return  merchandiseDAO.queryMerById(int_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public int deleteMerById(String id){
		try {
			int int_id = Integer.parseInt(id);
			return  merchandiseDAO.deleteMerById(int_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	public List<MerchandiseModel> findMerListByCateAndNameKey(String nameKey,
			String cateKey) {
		
		int category = Integer.parseInt(cateKey);
		try{			
			List<MerchandiseModel> merList = merchandiseDAO.queryMerListByCateAndNameKey(nameKey,category);
			return merList;
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	public int deleteCateById(String id) {
		try {
			int int_id = Integer.parseInt(id);
			return  merchandiseDAO.deleteCateById(int_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	public int addCate(String cateId, String cateName,String cateDesc) {
		try {
			int int_cateId = Integer.parseInt(cateId);
			return  merchandiseDAO.insertCate(int_cateId,cateName,cateDesc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	public int updateMer(int int_id, int int_category, String merName,double double_price, double double_sprice, String merModel,String picture, String merDesc, String manufacturer,String leaveFactoryDate, int int_special) 
	{
		try {
			return  merchandiseDAO.updateMer(int_id,int_category,merName,double_price,double_sprice,merModel,picture, merDesc, manufacturer,leaveFactoryDate,int_special);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
		
	}
	public int addMer(int int_category, String merName, double double_price,
			double double_sprice, String merModel, String picture,
			String merDesc, String manufacturer, String leaveFactoryDate,
			int int_special) {
		try {
			return  merchandiseDAO.addMer(int_category,merName,double_price,double_sprice,merModel,picture, merDesc, manufacturer,leaveFactoryDate,int_special);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}	
}